package com.douqu.game.fileManager;

import com.bean.core.util.EncryptUtils;
import com.bean.core.util.FileUtils;
import com.douqu.game.MenuManager;
import com.douqu.game.core.util.LogUtils;

import java.io.File;
import java.io.IOException;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-01-28 15:14
 */
public class EncodeUtils {

    public static void main(String[] args) throws IOException
    {
        String str = FileUtils.readFile("D:\\Accessory");
        String s = EncryptUtils.decode(str);
        System.out.println(s);

    }

    public static void encode()
    {
        String outPath = "data";
        File file = new File("in");
        File[] files = file.listFiles();
        String str = "";
        for(File f : files)
        {
            str = FileUtils.readFile(f.getAbsolutePath(), System.lineSeparator());

            FileUtils.writeFile(outPath + "/" + f.getName(), EncryptUtils.encode(str));

            LogUtils.info("--------------------->加密完成 -> " + f.getName());
        }
    }

    public static boolean encode(String inPath, String outPath)
    {
        File file = new File(inPath);
        if(!file.isDirectory())
            return false;

        if(!new File(outPath).isDirectory())
            return false;

        File[] files = file.listFiles();
        String str = "";
        for(File f : files)
        {
            if(f.getName().indexOf(".") != -1)
                continue;

            str = FileUtils.readFile(f.getAbsolutePath(), System.lineSeparator());

            FileUtils.writeFile(outPath + "/" + f.getName(), EncryptUtils.encode(str));

            MenuManager.println("加密文件成功 --------> " + f.getName());
        }

        return true;
    }





}
